home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
-
- mini.windows.c
-
- window functions for MiniEdit
-
- *********************************************************************/
-
- #include <QuickDraw.h>
- #include <MacTypes.h>
- #include <WindowMgr.h>
- #include <TextEdit.h>
- #include <ControlMgr.h>
- #include <EventMgr.h>
-
- #include "MiniEdit.h"
-
- extern WindowRecord wRecord;
- extern WindowPtr myWindow;
- extern ControlHandle vScroll;
- extern TEHandle TEH;
- extern char dirty;
- extern Str255 theFileName;
- extern int linesInFolder;
-
-
- SetUpWindows()
- {
- Rect destRect, viewRect;
- Rect vScrollRect;
- FontInfo myInfo;
- int height;
-
- SetPort((myWindow = GetNewWindow( windowID, &wRecord, -1L )));
- TextFont(4);
- TextSize(9);
- vScrollRect = (*myWindow).portRect;
- vScrollRect.left = vScrollRect.right-15;
- vScrollRect.right += 1;
- vScrollRect.bottom -= 14;
- vScrollRect.top -= 1;
- vScroll = NewControl( myWindow, &vScrollRect, "\p", 1, 0, 0, 0,
- scrollBarProc, 0L);
-
- viewRect = thePort->portRect;
- viewRect.right -= SBarWidth;
- viewRect.bottom -= SBarWidth;
- InsetRect(&viewRect, 4, 4);
- TEH = TENew( &viewRect, &viewRect );
- SetView(thePort);
- dirty = 0;
- }
-
-
- AdjustText ()
-
- {
- int oldScroll, newScroll, delta;
-
- oldScroll = (**TEH).viewRect.top - (**TEH).destRect.top;
- newScroll = GetCtlValue(vScroll) * (**TEH).lineHeight;
- delta = oldScroll - newScroll;
- if (delta != 0)
- TEScroll(0, delta, TEH);
- }
-
-
- SetVScroll()
- {
- register int n;
-
- n = (**TEH).nLines-linesInFolder;
-
- if ((**TEH).teLength > 0 && (*((**TEH).hText))[(**TEH).teLength-1]=='\r')
- n++;
-
- SetCtlMax(vScroll, n > 0 ? n : 0);
- }
-
- ShowSelect()
-
- {
- register int topLine, bottomLine, theLine;
-
- SetVScroll();
- AdjustText();
-
- topLine = GetCtlValue(vScroll);
- bottomLine = topLine + linesInFolder;
-
- if ((**TEH).selStart < (**TEH).lineStarts[topLine] ||
- (**TEH).selStart >= (**TEH).lineStarts[bottomLine]) {
- for (theLine = 0; (**TEH).selStart >= (**TEH).lineStarts[theLine]; theLine++)
- ;
- SetCtlValue(vScroll, theLine - linesInFolder / 2);
- AdjustText();
- }
- }
-
- SetView(w)
- WindowPtr w;
- {
- (**TEH).viewRect = w->portRect;
- (**TEH).viewRect.right -= SBarWidth;
- (**TEH).viewRect.bottom -= SBarWidth;
- InsetRect(&(**TEH).viewRect, 4, 4);
- linesInFolder = ((**TEH).viewRect.bottom-(**TEH).viewRect.top)/(**TEH).lineHeight;
- (**TEH).viewRect.bottom = (**TEH).viewRect.top + (**TEH).lineHeight*linesInFolder;
- (**TEH).destRect.right = (**TEH).viewRect.right;
- TECalText(TEH);
- }
-
- UpdateWindow(theWindow)
- WindowPtr theWindow;
- {
- GrafPtr savePort;
-
- GetPort( &savePort );
- SetPort( theWindow );
- BeginUpdate( theWindow );
- EraseRect(&theWindow->portRect);
- DrawControls( theWindow );
- DrawGrowIcon( theWindow );
- TEUpdate( &theWindow->portRect, TEH );
- EndUpdate( theWindow );
- SetPort( savePort );
- }
-
-
-
-
- pascal void ScrollProc(theControl, theCode)
- ControlHandle theControl;
- int theCode;
- {
- int pageSize;
- int scrollAmt;
-
- if (theCode == 0)
- return ;
-
- pageSize = ((**TEH).viewRect.bottom-(**TEH).viewRect.top) /
- (**TEH).lineHeight - 1;
-
- switch (theCode) {
- case inUpButton:
- scrollAmt = -1;
- break;
- case inDownButton:
- scrollAmt = 1;
- break;
- case inPageUp:
- scrollAmt = -pageSize;
- break;
- case inPageDown:
- scrollAmt = pageSize;
- break;
- }
- SetCtlValue( theControl, GetCtlValue(theControl)+scrollAmt );
- AdjustText();
-
- }
-
- DoContent(theWindow, theEvent)
- WindowPtr theWindow;
- EventRecord *theEvent;
- {
- int cntlCode;
- ControlHandle theControl;
- int pageSize;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(theWindow);
- GlobalToLocal( &theEvent->where );
- if ((cntlCode = FindControl(theEvent->where, theWindow, &theControl)) == 0) {
- if (PtInRect( theEvent->where, &(**TEH).viewRect ))
- TEClick( theEvent->where, (theEvent->modifiers & shiftKey )!=0, TEH);
- }
- else if (cntlCode == inThumb) {
- TrackControl(theControl, theEvent->where, 0L);
- AdjustText();
- }
- else
- TrackControl(theControl, theEvent->where, &ScrollProc);
-
- SetPort(savePort);
- }
-
- MyGrowWindow( w, p )
- WindowPtr w;
- Point p;
- {
- GrafPtr savePort;
- long theResult;
- int oScroll;
- Rect r, oView;
-
- GetPort( &savePort );
- SetPort( w );
-
- SetRect(&r, 80, 80, screenBits.bounds.right, screenBits.bounds.bottom);
- theResult = GrowWindow( w, p, &r );
- if (theResult == 0)
- return;
- SizeWindow( w, LoWord(theResult), HiWord(theResult), 1);
-
- InvalRect(&w->portRect);
- oView = (**TEH).viewRect;
- oScroll = GetCtlValue(vScroll);
-
- SetView(w);
- HidePen();
- MoveControl(vScroll, w->portRect.right - SBarWidth, w->portRect.top-1);
- SizeControl(vScroll, SBarWidth+1, w->portRect.bottom - w->portRect.top-(SBarWidth-2));
- ShowPen();
-
-
- SetVScroll();
- AdjustText();
-
- SetPort( savePort );
- }
-
-
-
- CloseMyWindow()
- {
- HideWindow( myWindow );
- TESetSelect( 0, (**TEH).teLength, TEH );
- TEDelete( TEH );
- SetVScroll();
- SetUpFiles();
- }
-